import java.util.Stack;

public class MyQueue {

    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode head;

    public ListNode last;

    /**
     * 入队操作： 尾插法
     *
     * @param val
     */
    public void offer(int val) {
        ListNode node = new ListNode(val);
        if (head == null) {
            head = last = node;
        } else {
            last.next = node;
            node.prev = last;
            last = node;
        }
    }

    /**
     * 删除队头元素
     *
     * @return
     */
    public int poll() {

        int tmp = head.val;
        if (head == null) {
           return -1;
        }

        if (head == last) {
            head = null;
            last = null;
        } else {
            head = head.next;
            head.prev = null;
        }
        return tmp;
    }

    /**
     * 获取队头元素
     *
     * @return
     */
    public int peek() {
        if (head == null) {
            return -1;
        }

        return head.val;
    }


}